#!/usr/bin/env python

import difflib
import json
import urllib2
import urllib
import argparse

from settings import *


def post(url, data):
    req = urllib2.Request(url)
    data = urllib.urlencode(data)
    #enable cookie  
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
    response = opener.open(req, data)
    return response.read()

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("fname_path_01")
    parser.add_argument("fname_path_02")
    args = parser.parse_args()

    # def send_request(url, method, request_body=None, timeout=100):
    with open(args.fname_path_01, 'r') as f:
        fname_01_lines = f.read().splitlines()

    with open(args.fname_path_02, 'r') as f:
        fname_02_lines = f.read().splitlines()

    d = difflib.HtmlDiff()

    html_body = {'html_body' : d.make_file(fname_01_lines, fname_02_lines)}
    #print html_body
    print post(URL_ADDRESS, html_body)

if __name__ == "__main__":
    main()
